home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Amiga_Mail_Vol2 / Archives / Plain / so91.lha / Aspect / Aspect.txt < prev   
Encoding:
Text File  |  1991-10-23  |  6.9 KB  |  215 lines

  1. (c)  Copyright 1991 Commodore-Amiga, Inc.   All rights reserved.
  2. The information contained herein is subject to change without notice,
  3. and is provided "as is" without warranty of any kind, either expressed
  4. or implied.  The entire risk as to the use of this information is
  5. assumed by the user.
  6.  
  7.  
  8. Finding the Aspect Ratio
  9.  
  10.  
  11. by Carolyn Scheppner
  12.  
  13.  
  14.  
  15.  
  16. The pixel aspect ratio describes the ratio of the width (x Aspect) to
  17. height (y Aspect) of the pixels in a Screen or ViewPort.  In order to
  18. create a truly What-You-See-Is-What-You-Get graphics display on the Amiga,
  19. you need to find the pixel aspect ratio of the display mode you are using.
  20. With the proper aspect ratio, an application can correctly display and
  21. store ILBM files, can rotate objects properly, and can calculate the proper
  22. dimensions to draw true circles and squares so they appear the same on the
  23. Amiga display as they would on some other output device, like a laser
  24. printer.
  25.  
  26. Under 1.3 and the original Amiga chip set, relatively few display modes
  27. were available.  Under pre-2.0 versions of the OS, applications can use
  28. hard-coded values for the X/Y pixel aspect ratio.  The aspect ratios for
  29. the display modes available to the 1.3 system are ( xaspect / yaspect ):
  30.  
  31. NTSC Lores      44/52
  32. PAL Lores       44/44
  33.  
  34. Halve the X aspect for Hires modes.
  35. Halve the Y aspect for interlaced modes.
  36.  
  37. These aspect values are more accurate than the values in the original IFF
  38. document.
  39.  
  40. On PAL displays, the pixels of Lores screens and Hires Interlace screens
  41. are square, as they have an aspect ratio of 44/44 and 22/22, respectively.
  42. To draw a square 100 pixels wide in one of these PAL modes, you could
  43. simply draw a square that is 100 pixels x 100 pixels.  On a PAL Lores
  44. Interlace display, the Y resolution is doubled, making each pixel half as
  45. tall, so you would have to draw a rectangle that was 100 pixels x 200
  46. pixels to get the same size square.
  47.  
  48. On an NTSC display, pixels are not square.  Pixels on a Lores NTSC screen
  49. have an aspect ratio of 44/52 (or 11/13).  This means that each pixel is
  50. slightly narrower than it is high.
  51.  
  52. To draw a true square that is 100 pixels wide in an arbitrary display mode,
  53. it is necessary to calculate the correct height for the square based on the
  54. pixel aspect ratio.
  55.  
  56.     width / yAspect = height / xAspect
  57.  
  58. (in words, width is to yAspect as height is to xAspect)
  59.  
  60. If the X/Y aspect is 44/52 (Lores NTSC), the calculation would be:
  61.  
  62.     100 / 52 = height / 44
  63.  
  64.     height = (100 * 44) / 52 = 4400 / 52    /* solve for height */
  65.  
  66. Because this example uses only integer math, the ratio must be rounded to
  67. the nearest integer.  A fraction a/b (where a and b are integers) rounded
  68. to the nearest integer approximately equals:
  69.  
  70.     ( a + ( b / 2 ) )  /  b
  71.  
  72. apply this to the ratio above:
  73.  
  74.     height = ( 4400 + (52>>1) ) / 52      /* with rounding */
  75.     height = 4426/52 = 85.115384...       /* Approximate */
  76.     height = 85                           /* truncated */
  77.  
  78. Therefore, to be square on a 44/52 aspect screen, a 100 pixel wide square
  79. would have to be 85 pixels tall.
  80.  
  81. Under 2.0 and the ECS chip set, the Amiga display is more dynamic.  It has
  82. many new display modes, each of which has its own distinct pixel aspect
  83. ratio.  For this reason, it is not practical nor desirable to hard code the
  84. aspect ratios for the modes that you know about (except when running under
  85. 1.3).  When running under 2.0, the pixel aspect should be determined by
  86. querying the display database (see the article ``An Introduction to V36
  87. Screens and Windows'' from the September /October 1990 issue of Amiga Mail
  88. for more information on how to query the display database).  A valid
  89. DisplayInfo structure contains the X and Y aspect in the Resolution.x and
  90. Resolution.y fields.  When writing an ILBM under 2.0, use these pixel
  91. aspects from the display database for the BMHD chunk's xAspect and yAspect
  92. values.
  93.  
  94. The following example demonstrates how to determine the X and Y aspects
  95. under both release 2.0 and 1.3.
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102. ;/* getaspect.c - Execute me to compile me with SAS C 5.10
  103. LC -b1 -cfistq -v -y -j73 getaspect.c
  104. Blink FROM LIB:c.o,getaspect.o TO getaspect LIBRARY LIB:LC.lib,LIB:Amiga.lib
  105. quit
  106.  
  107. Gets X/Y pixel aspect of a screen's ViewPort
  108. */
  109.  
  110. #include <exec/types.h>
  111. #include <exec/memory.h>
  112. #include <libraries/dos.h>
  113. #include <intuition/intuition.h>
  114. #include <intuition/intuitionbase.h>
  115. #include <graphics/displayinfo.h>
  116. #include <graphics/gfxbase.h>
  117.  
  118. #include <clib/exec_protos.h>
  119. #include <clib/dos_protos.h>
  120. #include <clib/intuition_protos.h>
  121. #include <clib/graphics_protos.h>
  122. #include <stdlib.h>
  123. #include <stdio.h>
  124. #include <string.h>
  125.  
  126. #ifdef LATTICE
  127. int CXBRK(void) { return(0); }  /* Disable Lattice CTRL/C handling */
  128. int chkabort(void) { return(0); }  /* really */
  129. #endif
  130.  
  131.  
  132. #define MINARGS 1
  133.  
  134. UBYTE *vers = "\0$VER: getaspect 37.1";
  135. UBYTE *Copyright =
  136.   "getaspect v37.1\nCopyright (c) 1990 Commodore-Amiga, Inc.  All Rights Reserved";
  137. UBYTE *usage = "Usage: getaspect";
  138.  
  139. void bye(UBYTE *s, int e);
  140. void cleanup(void);
  141.  
  142. struct Library *IntuitionBase;
  143. struct Library *GfxBase;
  144.  
  145. void main(int argc, char **argv)
  146.     {
  147.     struct Screen *first;
  148.     struct ViewPort *vp;
  149.     struct DisplayInfo DI;
  150.     ULONG  modeid;
  151.     UBYTE  xAspect, yAspect;
  152.  
  153.     if(((argc)&&(argc<MINARGS))||(argv[argc-1][0]=='?'))
  154.     {
  155.     printf("%s\n%s\n",Copyright,usage);
  156.     bye("",RETURN_OK);
  157.     }
  158.  
  159.     /* We will check later to see if we can call V36 functions */
  160.     IntuitionBase = OpenLibrary("intuition.library",34);
  161.     GfxBase = OpenLibrary("graphics.library",34);
  162.     if((!IntuitionBase)||(!GfxBase))
  163.     bye("Can't open intuition or graphics library",RETURN_FAIL);
  164.  
  165.     printf("Using front screen's ViewPort (for example purposes only):\n");
  166.  
  167.     first = ((struct IntuitionBase *)IntuitionBase)->FirstScreen;
  168.     vp = &first->ViewPort;
  169.  
  170.     xAspect = 0;    /* So we can tell when we've got it */
  171.  
  172.     if(GfxBase->lib_Version >= 36)
  173.     {
  174.         modeid = GetVPModeID(vp);
  175.  
  176.         if(GetDisplayInfoData(NULL, (UBYTE *)&DI, sizeof(struct DisplayInfo),
  177.         DTAG_DISP, modeid))
  178.         {
  179.         printf("Running 2.0,  ViewPort modeid is $%08lx\n",modeid);
  180.         xAspect = DI.Resolution.x;
  181.         yAspect = DI.Resolution.y;
  182.         printf("Pixel  xAspect=%ld  yAspect=%ld\n",xAspect, yAspect);
  183.         printf("PaletteRange is %ld\n",DI.PaletteRange);
  184.         }
  185.     }
  186.  
  187.     if(!xAspect)  /* pre-2.0 or GetDisplayInfoData failed */
  188.     {
  189.     modeid = vp->Modes;
  190.     printf("Not running 2.0, ViewPort mode is $%04lx\n",modeid);
  191.         /* default lores pixel ratio */
  192.         xAspect = 44;
  193.         yAspect = ((struct GfxBase *)GfxBase)->DisplayFlags & PAL  ? 44 : 52;
  194.         if(modeid & HIRES)      xAspect = xAspect >> 1;
  195.         if(modeid & LACE)       yAspect = yAspect >> 1;
  196.     printf("Pixel  xAspect=%ld  yAspect=%ld\n",xAspect, yAspect);
  197.         }
  198.  
  199.     bye("",RETURN_OK);
  200.     }
  201.  
  202.  
  203. void bye(UBYTE *s, int e)
  204.     {
  205.     cleanup();
  206.     exit(e);
  207.     }
  208.  
  209. void cleanup()
  210.     {
  211.     if(GfxBase) CloseLibrary(GfxBase);
  212.     if(IntuitionBase)   CloseLibrary(IntuitionBase);
  213.     }
  214.  
  215.